﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Logging;

namespace API.Controllers
{
    [ApiController]
    [Route("[controller]/[action]")]
    //设置授权访问

    //[AllowAnonymous]//设置匿名访问
    public class WeatherForecastController : ControllerBase
    {
        private static readonly string[] Summaries = new[]
        {
            "Freezing", "Bracing", "Chilly", "Cool", "Mild", "Warm", "Balmy", "Hot", "Sweltering", "Scorching"
        };

        private readonly ILogger<WeatherForecastController> _logger;

        public WeatherForecastController(ILogger<WeatherForecastController> logger)
        {
            _logger = logger;
        }



        [HttpGet]
        [AllowAnonymous]
        public IEnumerable<string> Get()
        {
            string[] arrry = new string[] { "value1", "value2", "value3", "value4", "value2" };
            //arrry = arrry.;
            return arrry.ToArray().Distinct();
        }


        //受保护的API,需要授权才能访问
        //验证输入的令牌以确保它来自可信任的发布者（IdentityServer）;
        // 验证令牌是否可用于该 api（也就是 Scope）。
        //dentityServer4.AccessTokenValidation 通过newGet添加
        [Authorize]
        [HttpGet(Name = nameof(GetAuth))]
        public IEnumerable<string> GetAuth()
        {
            string[] arrry = new string[] { "这是需要授权验证的接口，你已经授权通过，能看到" };

            return arrry.ToArray().Distinct();
        }
    }
}
